/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MySqlAccess;

import java.sql.ResultSet;

/**
 *
 * @author LNThanh
 */
public class PermalinkMapping 
{
    public static String MappingByID(int postID)
    {
        String query = "SELECT meta_value FROM wp_postmeta WHERE post_id=" + postID + " and meta_key=\"syndication_permalink\"";
        return Mapping(query);
    }

    public static String Mapping(String query)
    {
        String result = "";
        try
        {                     
            DataAcessHelper da = DataAcessHelper.GetInstance();
            ResultSet rs =  da.ExcuteQuery(query);            
            
            rs.beforeFirst();
            int idxValue = rs.findColumn("meta_value");
            while(rs.next())
            {
                String url = rs.getString(idxValue).trim();
                if (!url.isEmpty())
                {
                    return url;
                }
                else
                {
                    int i = 0;
                    i = 1;
                    
                }                
            }
            rs.close();
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        
        return "";
    }
}
